﻿using com.IronOne.BoardPACWinAppBO.Settings;
using com.IronOne.BoardPACWinAppService.Auth;
using com.IronOne.BoardPACWinAppService.Init;
using com.IronOne.BoardPACWinAppUtil.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Settings Flyout item template is documented at http://go.microsoft.com/fwlink/?LinkId=273769

namespace CompleteReader.Settings
{
    public sealed partial class About : SettingsFlyout
    {
        private IAuthService _authService;

        public About()
        {
            this.InitializeComponent();
            _authService = new AuthService();

            CopyrightTextBlock.Text = DateTime.Now.Year + " IronOne Technologies (Pvt) Ltd.";

            //AppNameTextBlock.Text = Windows.ApplicationModel.Package.Current.DisplayName + AppNameTextBlock.Text;
            //BuildTextBlock.Text += " " + Windows.ApplicationModel.Package.Current.Id.Version.Revision;
        }

        private async void SettingsFlyout_Loaded(object sender, RoutedEventArgs e)
        {
            string version = string.Format("{0}.{1}.{2}", Windows.ApplicationModel.Package.Current.Id.Version.Major, Windows.ApplicationModel.Package.Current.Id.Version.Minor, Windows.ApplicationModel.Package.Current.Id.Version.Build);
            CurrentVersionTextBlock.Text = version;

            AppSettingModel asm = await _authService.GetAppVersions();
            if (asm == null) return;
            CurrentWebVersionTextBlock.Text = asm.CurrentWebVersion;
            CurrentMinWebVersionTextBlock.Text = asm.MinWebVersion;
        }

        private void SettingsFlyout_Unloaded(object sender, RoutedEventArgs e)
        {
            _authService = null;
        }
    }
}
